package com.aboo.file2;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

public class ReadFile {

    public static void main(String[] args) throws Exception {
        String file = "D://file1.txt";
        BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
        ReadKit readKit = new ReadKit(br);

        ExecutorService executor = Executors.newFixedThreadPool(8);
        List<Future<Boolean>> taskList = new ArrayList<>(8);
        for (int i = 0; i < 5; i++) {
            Future<Boolean> future = executor.submit(new ReadCallable(readKit));
            taskList.add(future);
        }

        for (Future<Boolean> task : taskList) {
            System.out.println(task.get(10L, TimeUnit.SECONDS));
        }
        br.close();
        executor.shutdown();
    }

}
